// @see https://cn.vitejs.dev/guide/build.html#library-mode

import { resolve } from "path";
import { defineConfig } from "vite";
import pkg from "./package.json";

const namespace = pkg.namespace || "feng3d";
const external = pkg.standalone ? [] : Object.keys(pkg.dependencies || []);
const globals = () => namespace;

export default defineConfig({
    define: {
        __DEV__: process.env.NODE_ENV === 'development' ? true : false
    },
    publicDir: false,
    build: {
        lib: {
            // Could also be a dictionary or array of multiple entry points
            entry: resolve(__dirname, "src/index.ts"),
            name: namespace,
            // the proper extensions will be added
            fileName: "index",
        },
        minify: true,
        sourcemap: false,
        rollupOptions: {
            // 确保外部化处理那些你不想打包进库的依赖
            external,
            output: {
                // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
                globals,
            },
        },
    },
});

